package classroom;

import java.util.concurrent.atomic.AtomicInteger;

public class Test1 {
    public static void main(String[] args) {
        AtomicInteger ai = new AtomicInteger(10);
        //获取值
        System.out.println(ai.get());
        //自增1，返回自增前值
        int i = ai.getAndIncrement();
        System.out.println(i);
        //自增1，返回自增后值
        int i1 = ai.incrementAndGet();
        System.out.println(i1);
        //相加，打印出
        int i2 = ai.addAndGet(20);
        System.out.println(i2);
        System.out.println(ai.get());
        System.out.println("----------");
        //设置新值，打印
        int i3 = ai.getAndAdd(10);
        System.out.println(i3);
        System.out.println(ai.get());
    }
}
